package com.yunshipei.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yunshipei.enterplorer.R;

import java.util.List;

/**
 * Created by PC on 2016/7/27.
 */
public class DepartmentNameAdapter extends RecyclerView.Adapter implements View.OnClickListener {
    private List<String> list;
    private OnItemClickListener listener;

    public DepartmentNameAdapter(List<String> list) {
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_department_show, null);
        ViewHolder holder = new ViewHolder(view);
        holder.department_name = (TextView) view.findViewById(R.id.department_naem);
        holder.backview = (ImageView) view.findViewById(R.id.department_right_arrow);
        holder.department_name.setOnClickListener(this);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        String name = list.get(position);
        ((ViewHolder) holder).department_name.setTag(position);
        ((ViewHolder) holder).department_name.setText(name);
        if (position == 0) {
            ((ViewHolder) holder).backview.setVisibility(View.GONE);
        }else {
            ((ViewHolder) holder).backview.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void onClick(View view) {
        if (listener != null) {
            listener.onItemClick(view, (int) view.getTag());
        }
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        public TextView department_name;
        public ImageView backview;

        public ViewHolder(View itemView) {
            super(itemView);
        }
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

}
